/**
* 存储类，封装uni自带的存储方法.
* @overview
    //存储，获取，删除，清除
* @example
    //new Storage().get(key)
*/

class Storage {
	// 存储
	set(name, data, isObject = true) {
		uni.setStorageSync(name, JSON.stringify(data))
	}

	// 获取
	get(name, isObject = true) {
		let data = uni.getStorageSync(name)
		return data ? JSON.parse(data) : ''
	}

	// 删除且支持链式调用
	remove(name) {
		return new Promise((resolve, reject) => {
			uni.removeStorageSync(name)
			resolve()
		})
	}

	// 清除全部缓存
	clear() {
		uni.clearStorageSync()
	}
}

export default new Storage()
